//
//  ViewController.m
//  手势3
//
//  Created by mac on 15-12-21.
//  Copyright (c) 2015年 chenjianzhuo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    UIView *view;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    view = [[UIView alloc] initWithFrame:CGRectMake(10, 200, 50, 50)];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onPan:)];
    [view addGestureRecognizer:pan];
    
}

- (void)onPan:(UIPanGestureRecognizer *)pan{
    CGPoint p = [pan translationInView:self.view];
    CGRect rect = view.frame;
    rect.origin.x += p.x;
    rect.origin.y += p.y;
    pan.view.frame = rect;
    
    
    [pan setTranslation:CGPointZero inView:self.view];
}

//-(void)onPinch:(UIPanGestureRecognizer *)pinch
//{
//    pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
